﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
    /// <summary>
    /// 数据访问类ALARM_FILTERMAP。
    /// </summary>
    public class ALARM_FILTERMAP
    {
        public ALARM_FILTERMAP()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string USERID, string FILTERID, string MONITORID, string ISUSED)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ALARM_FILTERMAP");
            strSql.Append(" where USERID=:USERID and FILTERID=:FILTERID and MONITORID=:MONITORID and ISUSED=:ISUSED ");
            OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":FILTERID", OracleType.VarChar,50),
					new OracleParameter(":MONITORID", OracleType.VarChar,50),
					new OracleParameter(":ISUSED", OracleType.VarChar,50)};
            parameters[0].Value = USERID;
            parameters[1].Value = FILTERID;
            parameters[2].Value = MONITORID;
            parameters[3].Value = ISUSED;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(FiberRMS.Model.AlarmManager.ALARM_FILTERMAP model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ALARM_FILTERMAP(");
            strSql.Append("USERID,FILTERID,MONITORID)");
            strSql.Append(" values (");
            strSql.Append(":USERID,:FILTERID,:MONITORID)");
            OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":FILTERID", OracleType.VarChar,10),
					new OracleParameter(":MONITORID", OracleType.VarChar,50)};
            parameters[0].Value = model.USERID;
            parameters[1].Value = model.FILTERID;
            parameters[2].Value = model.MONITORID;

            int i = OracleHelper.ExecuteSql(strSql.ToString(), parameters);
            if (i > 0)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(FiberRMS.Model.AlarmManager.ALARM_FILTERMAP model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ALARM_FILTERMAP set ");
            strSql.Append("USERID=:USERID,");
            strSql.Append("FILTERID=:FILTERID,");
            strSql.Append("MONITORID=:MONITORID");
            strSql.Append(" where USERID=:USERID and FILTERID=:FILTERID and MONITORID=:MONITORID and ISUSED=:ISUSED ");
            OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":FILTERID", OracleType.VarChar,10),
					new OracleParameter(":MONITORID", OracleType.VarChar,50)};
            parameters[0].Value = model.USERID;
            parameters[1].Value = model.FILTERID;
            parameters[2].Value = model.MONITORID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string USERID, string FILTERID, string MONITORID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete ALARM_FILTERMAP ");
            strSql.Append(" where USERID=:USERID and FILTERID=:FILTERID and MONITORID=:MONITORID ");
            OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":FILTERID", OracleType.VarChar,50),
					new OracleParameter(":MONITORID", OracleType.VarChar,50)};
            parameters[0].Value = USERID;
            parameters[1].Value = FILTERID;
            parameters[2].Value = MONITORID;            

            int i = OracleHelper.ExecuteSql(strSql.ToString(), parameters);
            if (i > 0)
                return true;
            return false;
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FiberRMS.Model.AlarmManager.ALARM_FILTERMAP GetModel(string USERID, string FILTERID, string MONITORID, string ISUSED)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select USERID,FILTERID,MONITORID from ALARM_FILTERMAP ");
            strSql.Append(" where USERID=:USERID and FILTERID=:FILTERID and MONITORID=:MONITORID and ISUSED=:ISUSED ");
            OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":FILTERID", OracleType.VarChar,50),
					new OracleParameter(":MONITORID", OracleType.VarChar,50),
					new OracleParameter(":ISUSED", OracleType.VarChar,50)};
            parameters[0].Value = USERID;
            parameters[1].Value = FILTERID;
            parameters[2].Value = MONITORID;
            parameters[3].Value = ISUSED;

            FiberRMS.Model.AlarmManager.ALARM_FILTERMAP model = new FiberRMS.Model.AlarmManager.ALARM_FILTERMAP();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.USERID = ds.Tables[0].Rows[0]["USERID"].ToString();
                model.FILTERID = ds.Tables[0].Rows[0]["FILTERID"].ToString();
                model.MONITORID = ds.Tables[0].Rows[0]["MONITORID"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select USERID,FILTERID,MONITORID ");
            strSql.Append(" FROM ALARM_FILTERMAP ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ALARM_FILTERMAP";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

